package com.macoli.method_trace


import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes
import org.objectweb.asm.commons.AdviceAdapter

class MethodTraceMethodVisitor(
    private val className: String,
    nextMethodVisitor: MethodVisitor,
    access: Int,
    name: String?,
    descriptor: String?,
) : AdviceAdapter(Opcodes.ASM7, nextMethodVisitor, access, name, descriptor) {
    
    override fun onMethodEnter() {
        super.onMethodEnter()
        mv.visitLdcInsn("enter: $className.$name")
        mv.visitMethodInsn(
            Opcodes.INVOKESTATIC,
            "com/macoli/method_trace_log_helper/MethodTraceHelper",
            "methodEnter",
            "(Ljava/lang/String;)V",
            false
        )

    }

    override fun onMethodExit(opcode: Int) {
        super.onMethodExit(opcode)
        mv.visitLdcInsn("enter: $className.$name")
        mv.visitMethodInsn(
            Opcodes.INVOKESTATIC,
            "com/macoli/method_trace_log_helper/MethodTraceHelper",
            "methodExit",
            "(Ljava/lang/String;)V",
            false
        )
    }
}